﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VietPublisher.BSL.BK;
using VietPublisher.Repository.Repositories.Concrete;
using VietPublisher.BaseProject.Models;


namespace VietPublisher.Repositories.Interface
{
    public class OrderRepository : BaseRepository, IOrderRepository
    {
        public OrderRepository() { 
        }


        public List<ListOrder> GetOrderList()
        {
           // var orders = ContextBookStore.T_BK_Order.ToList();

            #region join muli table by LINQ
            var orders = (
                          from od in ContextBookStore.T_BK_Order                         
                          select new ListOrder()
                          {
                              Note = od.Note,
                              OrderCode= od.OrderCode,
                              OrderDate= od.OrderDate,
                              Status = od.Status,
                              Total =0,
                              UpdateDate= od.UpdateDate,
                              UserName = od.UserName
                          }
                           ).ToList();
            #endregion

            return orders;
        }

        public List<T_BK_Order> GetOrdersByDate(DateTime date)
        {
            List<T_BK_Order> orders = null;
            var ordersTempt = ContextBookStore.T_BK_Order.Where(p => p.OrderDate == date);
            if (orders != null) {
                orders = ordersTempt.ToList();
            }
            return orders;
        }

        public List<T_BK_Order> GetOrdersByAccount(string userName)
        {
            List<T_BK_Order> orders = null;
            var ordersTempt = ContextBookStore.T_BK_Order.Where(p => p.UserName == userName);
            if (ordersTempt != null)
            {
                orders = ordersTempt.ToList();
            }
            return orders;
        }
    }
}
